`
https://leetcode.cn/problems/vowel-spellchecker/
`

/**
 * @param {string[]} wordlist
 * @param {string[]} queries
 * @return {string[]}
 */
var spellchecker = function (wordlist, queries) {
  // 使用哈希表来实现快速读取

  // 存储源数据
  const wordsRaw = new Set()
  // 存储 lower -> raw
  const wordsLow = new Map()
  // 存储 lower and vowel -> raw
  const wordsVow = new Map()

  // 将元音字母省略掉
  const devowel = (word) => word.split('').map((c) => isVowel(c) ? '*' : c).join('')

  // 判断字母是否为元音字母
  const isVowel = (c) => ['a', 'e', 'i', 'o', 'u'].includes(c.toLowerCase())

  // 解析查询单词
  const solve = (query) => {
    // 根据题目规则一层层往下查
    if (wordsRaw.has(query)) return query
    const queryL = query.toLowerCase()
    if (wordsLow.has(queryL)) return wordsLow.get(queryL)
    const queryLV = devowel(queryL)
    if (wordsVow.has(queryLV)) return wordsVow.get(queryLV)
    return ""
  }

  // 将数据存储到哈希表中
  for (const word of wordlist) {
    wordsRaw.add(word)

    const wordL = word.toLowerCase()
    if (!wordsLow.has(wordL)) wordsLow.set(wordL, word)

    const wordLV = devowel(wordL)
    if (!wordsVow.has(wordLV)) wordsVow.set(wordLV, word)
  }

  // 返回每个查询的结果
  return queries.map((query) => solve(query));
};